Fix PathUtils.IsSymlink throwing on common lstat failures#183
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts PathUtils.IsSymlink to treat common lstat failures (e.g., missing path / access denied) as non-exceptional and return false, improving robustness when walking directory trees. It also introduces NUnit coverage for the updated behavior and attempts to expose internals to the test assembly.
Changes:
- Update
PathUtils.IsSymlinkto returnfalsefor specificerrnovalues instead of throwing. - Add
PathUtilsTeststo validate symlink detection and non-existent-path behavior. - Add an
InternalsVisibleToentry intended to allow tests to access internal types.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| Xamarin.MacDev/Xamarin.MacDev.csproj | Adds InternalsVisibleTo for the tests assembly. |
| Xamarin.MacDev/PathUtils.cs | Updates IsSymlink error handling for lstat failures. |
| tests/PathUtilsTests.cs | Adds new NUnit tests for PathUtils behavior. |
a1ab463 to
172d659
Compare
IsSymlink previously threw an exception for any lstat failure, including ENOENT (file not found) and EACCES (permission denied). These are expected non-exceptional conditions — especially when walking directory trees to check for symlinks via IsSymlinkOrHasParentSymlink. Now returns false for ENOENT, EACCES, and ENOTDIR, and only throws for genuinely unexpected errno values. Uses named constants for clarity. Also adds InternalsVisibleTo for the test project and new PathUtilsTests (5 tests covering non-existent, regular, symlink, parent-walk, and ENOTDIR). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
172d659 to
ae7c268
Compare
- Remove unused 'using System;' from PathUtilsTests.cs - Add IsSymlinkOrHasParentSymlink_ReturnsTrue_WhenParentIsSymlink test that creates a symlink directory and verifies parent traversal Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rolfbjarne
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IsSymlinkpreviously threw for anylstatfailure, including file-not-found and permission-denied. These are expected when walking directory trees (e.g.IsSymlinkOrHasParentSymlink).Now returns
falsefor ENOENT (2), EACCES (13), and ENOTDIR (20), only throwing for genuinely unexpected errors.Testing
Added
PathUtilsTestswith 4 tests verifying behavior for non-existent files, regular files, symlinks, and parent-symlink traversal.Also adds
InternalsVisibleTofor the test assembly.